from .layers import *

import os
import numpy as np
import tensorflow as tf

initializer = tf.contrib.layers.xavier_initializer()


def miccai2019_kidney(inputs, training, keep_prob):
    # http://results.kits-challenge.org/miccai2019/manuscripts/Isensee_1.pdf
    concat_tensor = {}
    down_features = [60, 120, 240, 320, 320]
    up_features = [320, 240, 120, 60, 30]

    tensor = inputs
    # tensor = tf.concat([image, memory], -1)
    tensor = Conv(tensor, 30, 3, 1, 'cir')
    tensor = Conv(tensor, 30, 3, 1, 'cir')

    for idx, feature in enumerate(down_features):
        concat_tensor[idx] = tensor
        tensor = Conv(tensor, feature, 3, 2, 'cir')
        tensor = Conv(tensor, feature, 3, 1, 'cir')

    for idx, feature in enumerate(up_features):
        upsampled = Upsamping3d(tensor)
        concated = tf.concat([concat_tensor[4 - idx], upsampled], -1)
        tensor = Conv(concated, feature, 3, 1, 'cir')
        tensor = Conv(tensor, feature, 3, 1, 'cir')

    return tf.layers.conv3d(tensor, 1, 1, padding="same",
                            use_bias=True, activation=tf.nn.sigmoid,
                            kernel_initializer=initializer)


def miccai2019_kidney2(image, memory, keey):
    # http://results.kits-challenge.org/miccai2019/manuscripts/Isensee_1.pdf
    concat_tensor = {}
    down_features = [60, 120, 240, 320, 320]
    up_features = [320, 240, 120, 60, 30]

    tensor = tf.concat([image, memory], -1)
    tensor = Conv(tensor, 30, 3, 1, 'cir')
    tensor = Conv(tensor, 30, 3, 1, 'circiar')

    for idx, feature in enumerate(down_features):
        concat_tensor[idx] = tensor
        tensor = Conv(tensor, feature, 3, 2, 'c')
        tensor = Conv(tensor, feature, 3, 1, 'irciar')
        for j in range(idx + 1):
            tensor = Conv(tensor, feature, 3, 1, 'circiar')

    for idx, feature in enumerate(up_features):
        upsampled = Upsamping3d(tensor)
        concated = tf.concat([concat_tensor[4 - idx], upsampled], -1)
        tensor = Conv(concated, feature, 3, 1, 'cir')

    return tf.layers.conv3d(tensor, 1, 1, padding="same",
                            use_bias=True, activation=tf.nn.sigmoid,
                            kernel_initializer=initializer)